local sk__chenqing = fk.CreateSkill {

  name = "sk__chenqing",

  tags = {  },

}



sk__chenqing:addEffect(fk.EnterDying, {
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(sk__chenqing.name) and player:usedSkillTimes(sk__chenqing.name, Player.HistoryPhase) == 0 and
      #player.room:getOtherPlayers(target) > 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local to = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(target), Util.IdMapper), 1, 1,
      "#sk__chenqing-choose::"..target.id..":"..(player:usedSkillTimes(sk__chenqing.name, Player.HistoryGame) + 1), sk__chenqing.name, true)
    if #to > 0 then
      event:setCostData(self, to[1])
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(event:getCostData(self))
    to:drawCards(4, sk__chenqing.name)
    if to.dead or to:isNude() then return end
    local n = player:usedSkillTimes(sk__chenqing.name, Player.HistoryGame)
    local cards = room:askForDiscard(to, n, n, true, sk__chenqing.name, false, ".", "#sk__chenqing-discard::"..target.id..":"..n, true)
    local suits = {}
    for _, id in ipairs(cards) do
      if Fk:getCardById(id).suit ~= Card.NoSuit then
        table.insertIfNeed(suits, Fk:getCardById(id).suit)
      end
    end
    room:throwCard(cards, sk__chenqing.name, to, to)
    if #suits == #cards and not target.dead then
      room:useVirtualCard("peach", nil, to, target, sk__chenqing.name)
    end
  end,
})

return sk__chenqing